package cn.com.lms.business.course.persistence.repository;

import cn.com.lms.business.course.persistence.entity.FbCourseInfo;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface FbCourseInfoRepository extends BaseRepository<FbCourseInfo, Long> {


    @Modifying
    @Query(value = "update bnz_course_info set is_delete = 1 where id = ?1 ", nativeQuery = true)
    int updateCourseStatus(Long id);

    @Modifying
    @Query(value = "update bnz_course_info set is_over = 1 where id = ?1 ", nativeQuery = true)
    int updateCourseOver(Long id);

    @Query(value = "SELECT d.name , d.id as value,d.value as text FROM bnz_sys_dictionary d where type_id =" +
            "(select id from bnz_sys_dictionary_type dt where deleted=0 and dt.code = ?1) ", nativeQuery = true)
    List<Map<String, Object>> queryDictionaryList(String code);


    @Query(value = "SELECT * FROM bnz_course_info WHERE is_delete = '0' AND category_id = ?1", nativeQuery = true)
    List<FbCourseInfo> findByCategoryId(Long id);

    @Query(value = "SELECT t1.* FROM bnz_course_info t1 inner join bnz_group_course t2 on t1.id = t2.course_id WHERE t1.is_delete = '0' AND t2.group_id = ?1", nativeQuery = true)
    List<FbCourseInfo> findByGroupId(String groupId);



    @Query(value = "SELECT t1.course_file FROM bnz_course_info t1  WHERE  t1.id = ?1", nativeQuery = true)
    String getUrl(Long courseId);

    @Query(value = "SELECT t1.is_over FROM bnz_course_info t1  WHERE  t1.id = ?1", nativeQuery = true)
    String getIsOver(Long courseId);



}
